#ifndef __CHAR_NODE_H__
  #define __CHAR_NODE_H__

namespace char_memory_management {

//! A simple node for char_list

/*!
A minimal node implementation for char_list.
*/
  class char_node {
  private:
    const char_node *next;
    char *value; // array of characters
    char *p; // pointer to the next free place in the "values"
    const unsigned int max_size; // inclusive null-termination

    //! assignment operator: not allowed
    char_node &operator=(const char_node &n);

    //! copy constructor: not allowed
    char_node(const char_node &n);

  public:
    //! returns the value
    char *get_value() const {
      return value;
    }

    //! returns the number of free bytes in this node
    unsigned int get_free_size() const {
      return (max_size - (unsigned int) (p - value));
    }

    //! reserves the requested size and mark them as allocated
    char *allocate(unsigned int size) {
      //if (get_free_size() <= size)
        //throw (char*) "buffer is too small!";

      char *result = p;

      p += size;
      value[p - value] = '\0';
      p += 1; // because of null-termination

      return result;
    }

    //! sets the next node to this node
    void set_next(const char_node *next) {
      this->next = next;
    } // set_next

    //! returns the next node to this node
    const char_node *get_next() const {
      return next;
    } // get_next

    //! constructor
    char_node(char *value, unsigned int max_size) : next(0), value(value), p(value), max_size(max_size) {
      // nothing to do
    } // char_node

    //! destructor (non-virtual: please do not inherit from this class)
    ~char_node() {
      // nothing to do
    } // ~char_node
  }; // class char_node

} // namespace char_memory_management

#endif
